package com.kpiJavaTraining.bogdan.module2;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * collection for objects of type Question2
 * @author Bogdan Olexandr
 */
public class ListOfNode<T> implements Iterable<T> , Cloneable , Serializable {

	private static final long serialVersionUID = -5625201139915779555L;
	private List<T> list = new ArrayList<T>();
	
	/**
	 * method adds an item to the collection
	 * @param element
	 */
	public void add(T element){
		list.add(element);
	}
		
	/**
	 * method returns an iterator class
	 * @return Iterator
	 */
	@Override
	public Iterator<T> iterator() {
		return list.iterator();
	}

	public T getNode(int index){
		return list.get(index);
	}
	
	public int getCountOfNode() {	
		return list.size();
	}
	
	@Override
	protected ListOfNode<T> clone() throws CloneNotSupportedException {	

		ListOfNode<T> listOfNode = new ListOfNode<T>();
		for(T q : list){
			listOfNode.add(q);
		}
		return listOfNode;
	}
}